package com.atguigu.mybatis.lamda;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by Smexy on 2022/11/29
 */
public class StreamDemo
{
    public static void main(String[] args) {

        String [] array = {"a","b","c"};

        Stream<String> stream = Arrays.stream(array);

        List<Integer> list1 = Arrays.asList(1, 2, 3);

        Stream<Integer> stream1 = list1.stream();

        Stream<Integer> stream2 = Stream.of(1, 2, 3, 4, 5);

        //进行转换  stream2中的每个元素 + 10 ，取所有的奇数

        Stream<Integer> stream3 = stream2.map(new Function<Integer, Integer>()
        {
            @Override
            public Integer apply(Integer in) {
                return in + 10;
            }
        });

        Stream<Integer> stream4 = stream3.filter(new Predicate<Integer>()
        {

            //只留下返回true的
            @Override
            public boolean test(Integer in) {
                return in % 2 == 1;
            }
        });

        List<Integer> result = stream4.collect(Collectors.toList());

        System.out.println(result);

    }
}
